<!--#
layout("/layouts/platform.html"){
#-->
<div id="app"  v-cloak>
<!--
    <div class="head"><div class="headone"><i class="el-icon-menu"></i><span >样品信息</span></div></div>
-->
    <el-row class="header navbar bg-white">
        <div class="btn-group tool-button" style="line-height: 50px;">
            样品编号或名称：<el-input clearable placeholder="样品编号或名称" v-trim v-model="pageForm.searchKeyword"  size="mini" style="width:180px;"></el-input>
            检验状态：<el-select v-trim v-model="pageForm.lczt" placeholder="检验状态" size="mini" style="width:180px;" clearable>
                <el-option v-for="item in allMap.lcztOptions" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
            </el-select>
            流转状态：<el-select v-trim v-model="pageForm.lzzt" placeholder="流转状态" size="mini" style="width:180px;" clearable>
                <el-option v-for="item in allMap.lzztOptions" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
            </el-select>
            <el-button slot="append" icon="el-icon-search" size="mini" @click="doSearch" circle></el-button>
        </div>
        <div class="pull-right offscreen-right" style="margin-right: 20px;line-height: 50px;">
            <!--#if(@shiro.hasPermission("bus.ypxx.jbxx.add")){#-->
            <el-tooltip class="item" effect="dark" content="样品登记">
                <el-button type="primary" icon="el-icon-plus"  size="mini" @click="openAdd" circle></el-button>
            </el-tooltip>
            <!--#}#-->
            <!--#if(@shiro.hasPermission("bus.ypxx.jbxx.Subm")){#-->
            <!--<el-tooltip class="item" effect="dark" content="批量提交">
                <el-button type="success" icon="el-icon-check"  size="mini"  @click="subm" circle></el-button>
            </el-tooltip>-->
            <!--#}#-->
            <!--#if(@shiro.hasPermission("bus.ypxx.jbxx.delete")){#-->
            <!--<el-tooltip class="item" effect="dark" content="批量删除">
                <el-button type="danger" icon="el-icon-delete"  size="mini"  @click="deleteYp" circle></el-button>
            </el-tooltip>-->
            <!--#}#-->
        </div>
    </el-row>
    <el-row class="el-table-container">
        <el-table :data="tableData" @sort-change='pageOrder' height="520"  border size="small" header-align="center" row-key="id"  style="width: 100%" @selection-change="handleSelectionChange">
<!--
            <el-table-column fixed="left" width="35"  type="selection"></el-table-column>
-->
            <el-table-column fixed="left" prop="userOnline" label="操作" width="120" header-align="center" align="center">
                <template slot-scope="scope">
                    <el-dropdown @command="dropdownCommand">
                        <el-button size="mini"><i class="ti-settings"></i><span class="ti-angle-down"></span></el-button>
                        <el-dropdown-menu slot="dropdown">
                            <!--#if(@shiro.hasPermission("bus.ypxx.jbxx.Subm")){#-->
                            <template v-if="scope.row.lczt==0  && userId == scope.row.opby">
                                <el-dropdown-item :command="{type:'Subm',id:scope.row.id,ypbh:scope.row.ypbh}">提交</el-dropdown-item>
                            </template>
                            <!--#}#-->
                            <!--#if(@shiro.hasPermission("bus.ypxx.jbxx.copy")){#-->
                            <el-dropdown-item  :command="{type:'copy',id:scope.row.id}">复制</el-dropdown-item>
                            <!--#}#-->
                            <template v-if="(scope.row.lczt==0 || scope.row.lzzt==0) && userId == scope.row.opby">
                                <!--#if(@shiro.hasPermission("bus.ypxx.jbxx.edit")){#-->
                                    <el-dropdown-item :command="{type:'edit',id:scope.row.id}">修改</el-dropdown-item>
                                <!--#}#-->
                                <!--#if(@shiro.hasPermission("bus.ypxx.jbxx.delete")){#-->
                                    <el-dropdown-item  :command="{type:'delete',id:scope.row.id,ypbh:scope.row.ypbh}">删除</el-dropdown-item>
                                <!--#}#-->
                            </template>
                            <el-dropdown-item  :command="{type:'detail',id:scope.row.id}">详情</el-dropdown-item>
                            <el-dropdown-item  :command="{type:'createAgreement',id:scope.row.id,ypbh:scope.row.ypbh}">委托单</el-dropdown-item>
                            <!--<template v-if="scope.row.lzzt > 0">
                                <el-dropdown-item  :command="{type:'createCirculation',id:scope.row.id}">流转单
                                </el-dropdown-item>
                            </template>-->
                        </el-dropdown-menu>
                    </el-dropdown>
                </template>
            </el-table-column>
            <el-table-column fixed="left" sortable="custom" prop="ypbh" label="样品编号" width="150px;" header-align="center"  show-overflow-tooltip></el-table-column>
            <el-table-column fixed="left" sortable="custom" prop="bgbh" label="报告编号" width="150px;" header-align="center"  show-overflow-tooltip></el-table-column>
            <el-table-column sortable="custom" prop="username" label="登记人" width="120px;" header-align="center"  show-overflow-tooltip></el-table-column>
            <el-table-column prop="lczt" label="检验状态" width="100px;" header-align="center"  show-overflow-tooltip>
                <template slot-scope="scope" ><span :class="'statusCss-'+scope.row.lczt"><i :class="'el-icon-'+scope.row.lczt"/>{{getDict(scope.row.lczt,allMap.lcztMap)}}</span></template>
            </el-table-column>
            <el-table-column prop="lzzt" label="流转状态" width="150px;" header-align="center"  show-overflow-tooltip>
                <template slot-scope="scope" >
                    <span :class="'lzstatusCss-'+scope.row.lzzt"><i :class="'lzel-icon-'+scope.row.lzzt"/>{{getDict(scope.row.lzzt,allMap.lzztMap)}}
                </span>
                    <span v-if="scope.row.lzzt<3"><span v-if="scope.row.status=='0'">(待接收)</span>
                    <span v-if="scope.row.status=='1'">(已接收)</span>
                    <span v-if="scope.row.status=='-1'">(已拒收)</span></span></template>
            </el-table-column>
            <el-table-column sortable="custom"  prop="ypmc" label="产品名称" width="150px;" header-align="center"  show-overflow-tooltip></el-table-column>
            <el-table-column sortable="custom" prop="jylx" label="检验类别" width="100px;" header-align="center" align="center" show-overflow-tooltip>
                <template slot-scope="scope" >{{getDict(scope.row.jylx,allMap.jylxMap)}}</template>
            </el-table-column>
            <el-table-column sortable="custom" prop="jyks" label="检验部门" width="100px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column prop="wtdw" label="委托单位" width="100px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column prop="ggxh" label="规格型号" width="100px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column prop="scrqpc" label="生产日期/批号" width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column prop="sb" label="商标" width="100px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column sortable="custom" prop="wcqx" label="完成期限" width="100px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column prop="" label="剩余时间" width="100px;" header-align="center" align="center" show-overflow-tooltip>
                <template slot-scope="scope" ><span :id="'foot'+scope.$index">{{getDay(scope.row.wcqx,scope.$index)}}</span></template>
            </el-table-column>
           <!-- <el-table-column prop="jyfy" label="检验费用" width="100px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column prop="" label="已收费用" width="100px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column prop="" label="缴费日期" width="100px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column prop="" label="缴费联系人" width="100px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>-->
        </el-table>
    </el-row>
    <el-row class="el-pagination-container">
        <el-pagination @size-change="pageSizeChange" @current-change="pageNumberChange" :current-page="pageForm.pageNumber" :page-sizes="[10, 20, 30, 50]"
                       :page-size="pageForm.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pageForm.totalCount">
        </el-pagination>
    </el-row>
    <el-drawer   title="详情" :visible.sync="drawer" direction="rtl" size="80%" @opened="openIframe" destroy-on-close>
        <iframe id="iframeDetail"  src="" width="100%" height="100%" frameborder="0" marginheight="0" ></iframe>
    </el-drawer>
</div>
<script>
    new Vue({
        el: "#app",
        data: function () {
            var allMap = {jylxMap:${jylxMap},lcztMap:${lcztMap},lzztMap:${lzztMap},lcztOptions:${lcztOptions},lzztOptions:${lzztOptions}};
            return {
                allMap:allMap,
                tableData: [],
                menuOptions: [],
                pageForm: {},
                multipleSelection: [],
                drawer: false,
                deltailURL:"",
                userId:"${userId}"
            }
        },
        methods: {
            pageOrder: function (column) {//按字段排序
                this.pageForm.pageOrderName = column.prop;
                this.pageForm.pageOrderBy = column.order;
                this.pageData();
            },
            pageNumberChange: function (val) {//页码更新操作
                this.pageForm.pageNumber = val;
                this.pageData();
            },
            pageSizeChange: function (val) {//分页大小更新操作
                this.pageForm.pageSize = val;
                this.pageData();
            },
            pageData: function () {//加载分页数据
                var self = this;
                sublime.showLoadingbar();//显示loading
                $.post(base + "/platform/bus/ypxx/jbxx/data", self.pageForm, function (data) {
                    sublime.closeLoadingbar();//关闭loading
                    if (data.code == 0) {
                        self.tableData = data.data.list;
                        self.pageForm.totalCount = data.data.totalCount;
                    } else {
                        self.$message({
                            message: data.msg,
                            type: 'error'
                        });
                    }
                }, "json");
            },
            doSearch: function () {
                this.pageForm.pageNumber = 1;
                this.pageData();
            },
            openAdd: function () {
                window.location.href="/platform/bus/ypxx/jbxx/add";
            },
            getDict: function (val,map) {
                val = val + "";
                if (val!= null && val!=undefined &&val!="" &&val!="null" &&val!="undefined"  && map!=null && map !=undefined){
                    var str = val.split(",");
                    var strname="";
                    for (var a=0;a<str.length;a++){
                        strname+=map[str[a]];
                        if(strname == null){
                            alert(1)
                        }
                        if(a<(str.length-1)){
                            strname+="/";
                        }
                    }
                    return strname;
                }
                return "";
            },
            dropdownCommand: function (command) {//监听下拉框事件
                var self = this;
                if ("edit" == command.type) {
                    window.location.href="/platform/bus/ypxx/jbxx/edit/"+command.id;
                }
                if ("copy" == command.type) {
                    window.location.href="/platform/bus/ypxx/jbxx/add?id="+command.id;
                }

                if ("Subm" == command.type) {
                    self.$confirm('此操作将提交' + command.ypbh, '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                        callback: function (a, b) {
                            if ("confirm" == a) {//确认后再执行
                                sublime.showLoadingbar();//显示loading
                                $.post(base + "/platform/bus/ypxx/jbxx/subm/" + command.id, {}, function (data) {
                                    sublime.closeLoadingbar();//关闭loading
                                    if (data.code == 0) {
                                        self.$message({
                                            message: data.msg,
                                            type: 'success'
                                        });
                                        self.doSearch();
                                    } else {
                                        self.$message({
                                            message: data.msg,
                                            type: 'error'
                                        });
                                    }
                                }, "json");
                            }
                        }
                    });
                }
                if ("detail" == command.type) {
                    //window.location.href="/platform/bus/ypxx/jbxx/detail/"+command.id;
                    this.drawer=true;
                    this.deltailURL="/platform/bus/ypxx/jbxx/detail/"+command.id;
                }
                if ("createAgreement" == command.type) {
                    sublime.showLoadingbar();//显示loading
                    $.post(base + "/platform/bus/ypxx/jbxx/createAgreement/" + command.id, {}, function (data) {
                        sublime.closeLoadingbar();//关闭loading
                        if (data.code == 0) {
                            self.$message({
                                message: data.msg,
                                type: 'success'
                            });
                            self.drawer = true;
                            var WOPISrc = "${AppDomain!}/platform/wopi/files/" + command.id + "xys.docx";
                            self.deltailURL = "${AppOfficeDomain!}/wv/wordviewerframe.aspx?wdAccPdf=1&WOPISrc=" + WOPISrc+"&_="+Math.floor(Math.random()*100000);
                        } else {
                            self.$message({
                                message: data.msg,
                                type: 'error'
                            });
                        }
                    }, "json");
                }
                if ("createCirculation" == command.type) {
                    sublime.showLoadingbar();//显示loading
                    $.post(base + "/platform/bus/ypxx/transfer/createCirculation/" + command.id, {}, function (data) {
                        sublime.closeLoadingbar();//关闭loading
                        if (data.code == 0) {
                            self.$message({
                                message: data.msg,
                                type: 'success'
                            });
                            self.drawer = true;
                            var WOPISrc = "${AppDomain!}/platform/wopi/files/" + command.id + "lzd.docx";
                            self.deltailURL = "${AppOfficeDomain!}/wv/wordviewerframe.aspx?wdAccPdf=1&WOPISrc=" + WOPISrc+"&_="+Math.floor(Math.random()*100000);
                        } else {
                            self.$message({
                                message: data.msg,
                                type: 'error'
                            });
                        }
                    }, "json");
                }
                if ("delete" == command.type) {
                    self.$confirm('此操作将删除 ' + command.ypbh, '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                        callback: function (a, b) {
                            if ("confirm" == a) {//确认后再执行
                                sublime.showLoadingbar();//显示loading
                                $.post(base + "/platform/bus/ypxx/jbxx/delete/" + command.id, {}, function (data) {
                                    sublime.closeLoadingbar();//关闭loading
                                    if (data.code == 0) {
                                        self.$message({
                                            message: data.msg,
                                            type: 'success'
                                        });
                                        self.doSearch();
                                    } else {
                                        self.$message({
                                            message: data.msg,
                                            type: 'error'
                                        });
                                    }
                                }, "json");
                            }
                        }
                    });
                }
            },
            openIframe:function(){
                $("#iframeDetail").attr("src",this.deltailURL);
            },
            handleClose: function() {
                this.drawer=false;
            },
            subm:function(){
                var self = this;
                if (self.multipleSelection.length == 0) {
                    self.$message({
                        message: "请选择要提交的数据",
                        type: 'warning'
                    });
                } else {
                    var ypbhs = [];
                    var ids = [];
                    self.multipleSelection.forEach(function (val) {
                        ypbhs.push(val.ypbh);
                        ids.push(val.id);
                    });
                    self.$confirm('此操作将提交 ' + ypbhs.toString(), '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                        callback: function (a, b) {
                            if ("confirm" == a) {//确认后再执行
                                sublime.showLoadingbar();//显示loading
                                $.post(base + "/platform/bus/ypxx/jbxx/subm/"+ids.toString(),{}, function (data) {
                                    sublime.closeLoadingbar();//关闭loading
                                    if (data.code == 0) {
                                        self.$message({
                                            message: data.msg,
                                            type: 'success'
                                        });
                                        self.doSearch();
                                    } else {
                                        self.$message({
                                            message: data.msg,
                                            type: 'error'
                                        });
                                    }
                                }, "json");
                            }
                        }
                    });
                }
            },
            deleteYp: function () {
                var self = this;
                if (self.multipleSelection.length == 0) {
                    self.$message({
                        message: "请选择要删除的数据",
                        type: 'warning'
                    });
                } else {
                    var ypbhs = [];
                    var ids = [];
                    var nodel=[];
                    self.multipleSelection.forEach(function (val) {
                        if(val.lczt==0 || (val.lczt==1 && val.lzzt!=1) || (val.lczt==3 && val.lzzt!=1)){
                            ypbhs.push(val.ypbh);
                            ids.push(val.id);
                        }else{
                            nodel.push(val.ypbh);
                        }
                    });
                    if(nodel.length>0){
                        self.$message({message: nodel.toString()+"不可删除！",type: 'error'});
                        return;
                    }
                    self.$confirm('此操作将删除 ' + ypbhs.toString(), '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                        callback: function (a, b) {
                            if ("confirm" == a) {//确认后再执行
                                sublime.showLoadingbar();//显示loading
                                $.post(base + "/platform/bus/ypxx/jbxx/delete", {ids: ids.toString()}, function (data) {
                                    sublime.closeLoadingbar();//关闭loading
                                    if (data.code == 0) {
                                        self.$message({
                                            message: data.msg,
                                            type: 'success'
                                        });
                                        self.doSearch();
                                    } else {
                                        self.$message({
                                            message: data.msg,
                                            type: 'error'
                                        });
                                    }
                                }, "json");
                            }
                        }
                    });
                }
            },
            handleSelectionChange: function (val) {
                this.multipleSelection = val;
            },
            getDay(day,index){
                if(day){
                    const today = new Date();
                    const inputDate = new Date(day);
                    const diffTime = inputDate-today;
                    const diffDays = Math.abs((diffTime / (1000 * 60 * 60 * 24)).toFixed(0));
                    if(diffTime<0&&diffDays>0){
                        $("#foot"+index).css("color","red");
                        return "逾期："+diffDays+"天";
                    }else{
                        return "剩余："+diffDays+"天";
                    }
                }else{
                    return "";
                }
            }
        },
        created: function () {
            this.doSearch();
        }
    });

    function nONull(val){
        if (val!= null && val!=undefined &&val!="" &&val!="null" &&val!="undefined" ){
            return true;
        }else{
            return false;
        }
    }
</script>
<!--#
}
#-->
